BIN_DIR=~/llvm-16.0.6/bin/bin

CPP=${BIN_DIR}/clang++
CC=${BIN_DIR}/clang
LLC=${BIN_DIR}/llc

LLVM_OPTION=--target=riscv64 -O2 -emit-llvm
LLC_OPTION=--march=riscv64
TEST_NAME=test

all: bc ll dump_debug_info

bc: ${TEST_NAME}.c
	${CC} ${LLVM_OPTION} ${TEST_NAME}.c -c -o ${TEST_NAME}.bc

ll: ${TEST_NAME}.c
	${CC} ${LLVM_OPTION} ${TEST_NAME}.c -S -o ${TEST_NAME}.ll

test:
	${LLC} ${LLC_OPTION} -view-dag-combine1-dags ${TEST_NAME}.ll

dump_debug_info:
	${LLC} ${LLC_OPTION} ${TEST_NAME}.ll -debug > ${TEST_NAME}_c_debug_info.txt 2>&1

.PHONY: vim clean

vim:
	ctags -R
	cscope -Rbkq

clean:
	rm -rf $(OBJ)
	rm -rf cscope.in.out cscope.out cscope.po.out tags
